#!/bin/sh 
#
#cmdtool $CD_MOUNT/find.sh

#echo "bef"
#kill -9 $PID_AUDIO
#echo "after"
if [ "$NETSCAPE_CATALYST" != "" ]; then
	if [ -r $NETSCAPE_CATALYST ]; then
		echo "Netscape is starting: using  "$NETSCAPE_CATALYST "..."
		$NETSCAPE_CATALYST -xrm "*useStderrDialog: False" -xrm "*strings.22130:This process will either launch\na demo from the Sun Solutions CD.\n\nProceed?\n" -geometry =665x770+0+0 $WWW_FIRST 2>&-
	else
		echo "Cannot execute $NETSCAPE_CATALYST";
	fi
else
	echo "Netscape is starting... "	

	if [ "$DEVCD_ENV" != "Solaris_1" ]; then

		$CD_MOUNT/.products/.bin/gui/$DEVCD_ENV/netscape -xrm "*useStderrDialog: False" -xrm "*strings.22130:This process will launch\na demo from the Sun Solutions CD.\n\nProceed?\n" -geometry =660x775+0+0 $WWW_FIRST 2>&-
	else
		$CD_MOUNT/.products/.bin/gui/$DEVCD_ENV/$SUNOS_VER/netscape -xrm "*useStderrDialog: False" -xrm "*strings.22130:This process will launch\na demo from the Sun Solutions CD.\n\nProceed?\n" -geometry =660x775+0+0 $WWW_FIRST 2>&-
	fi
fi

		
#
# clean-up
#
if [ -w /dev/audio ]; then 
	if [ $DEVCD_ENV != "Solaris_1" ]; then
        	audioplay -i $CD_MOUNT/.products/DEVCD/audio/thanks.au&
	else
        	cat $CD_MOUNT/.products/DEVCD/audio/thanks.au > /dev/audio&
	fi
fi

   perl -e '
if (-s "$ENV{\"HOME\"}/.netscape/preferences.SunCD") {
	if (open(PREFFILE, "$ENV{\"HOME\"}/.netscape/preferences.SunCD")) {
		while (<PREFFILE>) {
			if (/^([^:]*):([ 	]*.*)$/) {
				$Params{$1} = $2;
			}
		}
		close(PREFFILE);
	}
	if (open(PREFFILE, "$ENV{\"HOME\"}/.netscape/preferences") && open(NEWPREFFILE, ">$ENV{\"HOME\"}/.netscape/preferences.NewCD")) {
		while (<PREFFILE>) {
			if (m?^(AUTOLOAD_IMAGES):[ 	]*True?
			|| m?^(DISABLE_JAVA):[ 	]*False?
			|| m?^(DISK_CACHE_SIZE):[ 	]*3000?
			|| m?^(FTP_FILE_INFO):[ 	]*True?
			|| m?^(HOME_DOCUMENT):[ 	]*$ENV{"WWW_HOME"}?
			|| m?^(MEMORY_CACHE_SIZE):[ 	]*1000?
			|| m?^(NO_PROXY):[ 	]*localhost?
			|| m?^(PERSONAL_MAILCAP):[ 	]*/opt/ns-home/docs/demo/.DEVCD_mailcap?
			|| m?^(PERSONAL_MIME_TYPES):[ 	]*/opt/ns-home/docs/demo/conf/mime.types?
			|| m?^(PROXY_MODE):[ 	]*1?
			|| m?^(SHOW_DIRECTORY_BUTTONS):[ 	]*False?
			|| m?^(SHOW_SECURITY_BAR):[ 	]*True?
			|| m?^(SHOW_TOOLBAR):[ 	]*True?
			|| m?^(SHOW_URL):[ 	]*True?
			) {
				print NEWPREFFILE "$1:$Params{$1}\n";
			} else {
				print NEWPREFFILE;
			}
		}
		close(PREFFILE);
		close(NEWPREFFILE);
		rename("$ENV{\"HOME\"}/.netscape/preferences.NewCD", "$ENV{\"HOME\"}/.netscape/preferences");
		unlink("$ENV{\"HOME\"}/.netscape/preferences.SunCD");
	}
}
'

# kill httpd
if [ -r /opt/ns-home/docs/demo/logs/httpd.pid ]; then
	kill -9 `cat /opt/ns-home/docs/demo/logs/httpd.pid`
fi


if [ -h $HOME/.netscape/lock ]; then
	echo "Netscape seems to have crashed. Removing $HOME/.netscape/lock file."
	echo
	rm -rf $HOME/.netscape/lock
fi

# remove httpd config
# remove glimpse directory 
#if [ -d /opt/ns-home/docs/demo ]; then
	#echo "removing /opt/ns-home/docs/demo directory"
	#rm -rf /opt/ns-home/docs/demo
#fi

exit 0
